package bishi;

import java.util.Scanner;

/**
 * @Author liuhaoqi
 * @Date 2020/8/24 12:38
 * @Version 1.0
 */
public class Tencent03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for (int i = 0; i < T; i++) {
            int curnum = scanner.nextInt();
            int num = curnum;
            int digit =0 ;
            while (num > 10) {
                num /= 10;
                digit++;
            }

            while (digit > 0) {
                num *= 10;
                digit--;
            }
            int result = getSumofNum(num-1)+getSumofNum(curnum-num+1);
            System.out.println(result);
        }
    }

    public static int getSumofNum(int num) {
        int ans = 0;
        while (num != 0) {
            ans += num%10;
            num= num/10;
        }
        return ans;
    }
}
